local duanshuang = fk.CreateSkill {
    name = "kq__duanshuang",
}

duanshuang:addEffect("active", {
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "熔铸你与其的共计至多两张牌",
  can_use = function(self, player)
    return player:usedSkillTimes(duanshuang.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player and not player:isKongcheng() or not to_select:isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local black1,black2
    local cards = room:askToChooseCards(player, {
      target = player,
      min = 0,
      max = 2,
      flag = "he",
      skill_name = duanshuang.name
    })
    room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, duanshuang.name)
    if #cards ~= 0 then
        player:drawCards(1,duanshuang.name)
    end
    black1 = #table.filter(cards, function(id)
        return Fk:getCardById(id).color == Card.Black
    end)
    if #cards == 1 then
        cards = room:askToChooseCards(player, {
          target = target,
          min = 0,
          max = 1,
          flag = "he",
          skill_name = duanshuang.name
        })
        room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, duanshuang.name)
        if #cards ~= 0 then
        target:drawCards(1,duanshuang.name)
        end
        black2 = #table.filter(cards, function(id)
        return Fk:getCardById(id).color == Card.Black
        end)
    elseif #cards == 0 then
        cards = room:askToChooseCards(player, {
          target = target,
          min = 0,
          max = 2,
          flag = "he",
          skill_name = duanshuang.name
        })
        room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, duanshuang.name)
        if #cards ~= 0 then
        target:drawCards(1,duanshuang.name)
        end
        black2 = #table.filter(cards, function(id)
        return Fk:getCardById(id).color == Card.Black
        end)
    else
        black2 = 0
    end
    if black1 > black2 then
        room:useVirtualCard("duel", nil, player, target, duanshuang.name)
    elseif black1 < black2 then
        room:useVirtualCard("duel", nil, target, player, duanshuang.name)
    else
        target:setChainState(true, {
        who = player,
        reason = duanshuang.name
        })
        player:setChainState(true, {
        who = player,
        reason = duanshuang.name
        })
    end
  end,
})

Fk:loadTranslationTable {
    ["kq__duanshuang"] = "断霜",
    [":kq__duanshuang"] = "出牌阶段限一次，你可以选择你与一名其他角色的共计至多两张牌各熔铸之，然后因此失去黑色牌数较多的角色视为对另一方使用一张【决斗】，无较多的一方则你与其横置。"
}

return duanshuang